package com.example.firstapp;

import androidx.appcompat.app.AppCompatActivity;

import android.app.SearchManager;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.widget.Button;
import android.widget.EditText;

public class Test02Activity extends AppCompatActivity {
    Button bt_pageBaiDu, bt_pageMsg, bt_pageEmail, bt_pageMap, bt_pageWeb;
    EditText et_String;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_test02);

        //绑定组件
        bt_pageBaiDu = findViewById(R.id.bt_pageBaiDu);
        bt_pageMsg = findViewById(R.id.bt_pageMsg);
        bt_pageEmail = findViewById(R.id.bt_pageEmail);
        bt_pageMap = findViewById(R.id.bt_pageMap);
        bt_pageWeb = findViewById(R.id.bt_pageWeb);
        et_String = findViewById(R.id.et_String);

        /*
         * 监听组件
         * 用匿名监听组件
         */
        //打开百度按钮绑定
        bt_pageBaiDu.setOnClickListener(view -> {
            Intent intent = new Intent();
            intent.setAction(Intent.ACTION_VIEW);
            intent.setData(Uri.parse("http://www.baidu.com"));
            startActivity(intent);
        });

        //打开短信按钮绑定
        bt_pageMsg.setOnClickListener(view -> {
            Intent intent = new Intent(Intent.ACTION_SENDTO,
                    Uri.parse("smsto:10086"));
            intent.putExtra("sms_body", "cxll");
            startActivity(intent);
        });

        //打开邮箱按键绑定
        bt_pageEmail.setOnClickListener(view -> {
            Intent intent = new Intent();
            intent.setAction("android.intent.action.VIEW");
            intent.setData(Uri.parse("mailto:service@flag.com.tw"));
            intent.putExtra(Intent.EXTRA_CC, new String[]{"test@flag.com.tw"});
            startActivity(intent);
        });

        //打开地图按钮绑定
        bt_pageMap.setOnClickListener(view -> {
            Intent intent = new Intent(Intent.ACTION_MAIN);
            intent.addCategory(Intent.CATEGORY_APP_MAPS);
            startActivity(intent);
        });

        //web搜索资料
        bt_pageWeb.setOnClickListener(view -> {
            //百度引擎
            Intent intent = new Intent();
            intent.setAction(Intent.ACTION_VIEW);
            intent.setData(Uri.parse("https://www.baidu.com/s?wd="
                    + et_String.getText().toString()));
            startActivity(intent);
        });
    }

}